package org.springcloud.wisdom.springcloud_03_freshman.admin.controller;

import org.springcloud.wisdom.springcloud_03_freshman.admin.service.AdminTeacherService;
import org.springcloud.wisdom.springcloud_03_freshman.common.bean.ResponseData;
import org.springcloud.wisdom.springcloud_03_freshman.common.controller.BaseController;
import org.springcloud.wisdom.springcloud_03_freshman.index.login.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/admin/teacher")
public class AdminTeacherController extends BaseController {
    @Autowired
    AdminTeacherService adminTeacherService;
    @GetMapping("/page")
    public ResponseData<Object> teacherPage(
            @RequestParam("pageNum") int pageNum,
            @RequestParam("pageSize")int pageSize,
            @RequestParam(value = "tname",required = false)String tname,
            @RequestParam(value = "dept",required = false)Integer dept,
            @RequestParam(value = "tid",required = false) String tid
    ){
        return  returnObject(adminTeacherService.getTeacherPage(pageNum, pageSize, tname, dept, tid));
    }

    /**
     * 添加老师对象
     * @param teacher
     * @return
     */
    @PostMapping("/add")
    public ResponseData<Boolean> insertTeacher(Teacher teacher){
        System.out.println(teacher);
        return returnBoolean(adminTeacherService.addT(teacher));
    }

    /**
     * 逻辑上的删除老师
     * @param tid
     * @return
     */
    @DeleteMapping("/delete/{tid}")
    public ResponseData<Boolean> delete(@PathVariable("tid")String tid){
        return returnBoolean(adminTeacherService.deleteT(tid));
    }

    /**
     * 更新老师的密码或者所负责的院系
     * @param teacher
     * @return
     */
    @PutMapping("/update")
    public ResponseData<Boolean> updT(@RequestBody Teacher teacher){
        return returnBoolean(adminTeacherService.updateT(teacher));
    }
}
